<?php
class products extends CWidget
{
	public $_catID = null;
	public $_title = "";
	public function init()
	{
		$cs = Yii::app()->getClientScript();
		$cs->registerScriptFile(Yii::app()->theme->baseUrl."/js/easyTooltip.js");

		$cs->registerScript(
				'big-item',
				'$(".item-img").easyTooltip();',
				CClientScript::POS_READY
		);
		
		parent::init();
	}
	public function run()
	{
		$order = "lastest";
		$orderQuery="";
		if(isset($_POST['Products'])){
			$order = $_POST['Products']['order'];
			switch ($order){
				case 'hight':
					$orderQuery = "ORDER BY price DESC";
					break;
				case 'low':
					$orderQuery = "ORDER BY price ASC";
					break;
				default:
					$orderQuery = "";
					break;
			}
			
		}
		$total = FrontendShopProductsModel::getTotalProductByCat($this->_catID);
		$page = new CPagination($total);
		$itemOnPaging = 5;
		$page->pageSize = Yii::app()->params['perpage'];
		$curr_page = $page->getCurrentPage();
		$limit = 5;//$page->getLimit()
		$data = FrontendShopProductsModel::getProductByCat($this->_catID, $limit,$page->getOffset(), $orderQuery);
		$title = ($this->_catID==null)?$this->_title:FrontendShopCategoryModel::model()->findByPk($this->_catID)->title;
		$this->render('default', array(
					'data' =>$data,
					'page'=>$page,
					'catID'=>$this->_catID,
					'title'=>$title
				));
	}
}